Search this book | Previous | Table of contents | Next

Getting input via <ISINDEX>


The use of ISINDEX tags in HTML documents provide an easier way to supply into to our scripts.

With the addition of an ISINDEX tag returned in the HTML code sent by your .script files, you can create a simple text field facilitating input. After the end-user enters text into the field created by the ISINDEX tag, the script is called again and the the input is assigned to the http_search_args variable. The script hello-world-04.script illustrates this point:

-- define the standard HTTP header
set LF to ASCII character (10)
set CR to return
set CRLF to CR & LF
set http_10_header to "HTTP/1.0 200 OK" & CRLF & ¬
	"Server: MacHTTP" & CRLF & ¬
	"MIME-Version: 1.0" & CRLF & ¬
	"Content-type: text/html" & CRLF & CRLF

if http_search_args = "" then
	
	-- http_search_args is empty; request input via ISINDEX
	return http_10_header & ¬
		"<html>" & ¬
		"<head>" & ¬
		"<title>Hello!</title>" & ¬
		"<isindex>" & ¬
		"</head>" & ¬
		"<body>Hello! What is your name?" & ¬
		"</body>" & ¬
		"</html>"	
else
	
	-- http_search_args has value; return all variables
	return http_10_header & ¬
		"<html>" & ¬
		"<head>" & ¬
		"<title>Hello!</title>" & ¬
		"</head>" & ¬
		"<body>Hello!" & ¬
		"<p>http_search_args: " & http_search_args & ¬
		"<br>path_args: " & path_args & ¬
		"<br>post_args: " & post_args & ¬
		"<br>method: " & method & ¬
		"<br>client_address: " & client_address & ¬
		"<br>username:" & username & ¬
		"<br>password: " & password & ¬
		"<br>from_user:" & from_user & ¬
		"<br>server_name:" & server_name & ¬
		"<br>server_port:" & server_port & ¬
		"<br>script_name: " & script_name & ¬
		"<br>content_type: " & content_type & ¬
		"<br>referer: " & referer & ¬
		"<br>user_agent: " & user_agent & ¬
		"</body>" & ¬
		"</html>"	
end if
This script works by first checking the value of http_search_args. If is it empty, then the script returns an HTML document containing the ISINDEX tag in the head of the HTML file. The existence of this tag automatically makes an input field active on the end-user's client application.

After the end-user enters some data into the resulting input field, the client application appends the input to the script's URL and sends the URL back to the server requesting processing. Notice how the URL changed to include your input.

Finally, the script executes again, but the second time http_search_args has a value and the second half of the if-then-else statement is processed.

This technique is echoed in the following script emulating that popular song, "The Name Game":

-- define the standard HTTP header
set LF to ASCII character (10)
set CR to return
set CRLF to CR & LF
set http_10_header to "HTTP/1.0 200 OK" & CRLF & ¬
	"Server: MacHTTP" & CRLF & ¬
	"MIME-Version: 1.0" & CRLF & ¬
	"Content-type: text/html" & CRLF & CRLF

if http_search_args = "" then
	
	-- http_search_args is empty; request input via ISINDEX
	return http_10_header & ¬
		"<html><head>" & ¬
		"<title>Play the Name Game</title><isindex></head>" & ¬
		"<body>" & ¬
		"<H1>Play the Name Game</H1>" & ¬
		"</body></html>"	
else
	
	-- get our name
	set theName to word 1 of http_search_args as string
	
	-- initalize some variables for the next routine
	set foundVowel to 0
	set theCounter to 0
	set theSuffix to theName
	
	-- work through the name until we find the first vowel
	repeat until foundVowel is greater than 0
		
		-- increment our counter
		set theCounter to theCounter + 1
		
		-- get the next character
		set theCharacter to the first item of theSuffix
		
		-- check whether or not it is a vowel
		if "aeiouy" contains theCharacter or "AEIOUY" contains theCharacter then
			
			-- found it, exit
			set foundVowel to 1
			
		else
			
			-- left-hand truncate the name
			set theSuffix to items 2 through length of theSuffix as string
		end if
		
	end repeat
	
	-- compose the ryhmes
	set ryhmeOne to "B" & theSuffix
	set ryhmeTwo to "F" & theSuffix
	
	-- return the lyrics
	return http_10_header & ¬
		"<html><head>" & ¬
		"<title>The Name Game</title>" & ¬
		"<body>" & ¬
		"<h1>The Name Game</h1>" & ¬
		"<blockquote>" & theName & ", " & theName & ", Bo " & ryhmeOne & ".<br>" & return & ¬
		"Bananna fana, Fo " & ryhmeTwo & ".<br>" & return & ¬
		"Fe Fi Fo, " & ryhmeTwo & ".<br>" & return & ¬
		"<strong>" & theName & "</strong>!" & ¬
		"</body>" & ¬
		"</html>"	
end if
Again, the example is rather trivial. This script first defines an HTTP header. It then examines the value of http_search_args. If it has a null value, then an ISINDEX query is returned to the client. If http_search_args is not empty, then the script searches for the first vowel in the returned string and thus creates the ryhmes. Finally, the script returns the lyrics.

The point is that you can get input from the use of an ISINDEX HTML tag placed in the head of your HTML documents. You can then examine the value of http_search_args to perform some function and return the results.


Search this book | Previous | Table of contents | Next

Eric last edited this page on September 26, 1995. Please feel free to send comments.